<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="m" uri="/cutm_tags"%>
<html>
<head>
<title>信息交流</title>
<script type="text/javascript">
$(document).ready(function(){
	$('#msgForm').vaildAjax(function(data){
		BaseJs.alert(data);
		window.location.reload();
	});

	$('#submitButton').click(function(){
		var content = $('textarea[name=msg.content]').val();
		if(content==''){
			BaseJs.alert('内容不能为空！');
			return;
		}
		$('#msgForm').submit();
	});

	$('#deleteButton').click(function(){
		if(BaseJs.confirm('确定要清理吗？')){
			$.urlAjax('message/EditMessage!deleteAll',function(data){
				BaseJs.alert(data);
			});
		}
	});
});

function checkDelet(id){
	if(BaseJs.confirm('确定要删除吗？')){
		$.urlAjax('message/EditMessage!delete?msg.id='+id,function(){
			$('#pt' + id).remove();
		});
	}
}
</script>
</head>
<body>
<h2 class="title">信息交流</h2>
<table class="list">
	<tr>
		<th width="10%">时间</th>
		<th width="10%">发送人</th>
		<th width="70%">内容</th>
		<m:permiss permiss="DELETE_MESSAGE">
			<th width="10%">操作</th>
		</m:permiss>
	</tr>
	<s:iterator value="msgs.items">
		<tr id="pt${id }">
			<td><s:date name="createDate" format="yyyy-MM-dd HH:ss" /></td>
			<td><s:property value="createUser.name" /></td>
			<td><s:property value="content" /></td>
			<m:permiss permiss="DELETE_MESSAGE">
				<td><m:imgA img="delete" msg="删除"
					onclick="javascript:checkDelet(${id});" /></td>
			</m:permiss>
		</tr>
	</s:iterator>
</table>
<m:page value="${msgs}" />
<h2 class="title">发送信息</h2>
<s:form action="message/EditMessage" id="msgForm" method="post">
	<s:textarea name="msg.content" cssClass="required"></s:textarea>
	<input type="button" value="发送" id="submitButton">
	<m:permiss permiss="DELETE_MESSAGE">
	<input type="button" value="清理信息" id="deleteButton"></m:permiss>
</s:form>
</body>
</html>